package com.zzptc.easyshop.dao;

import com.zzptc.easyshop.db.MysqlDB;
import com.zzptc.easyshop.vo.Users;
import com.zzptc.easyshop.vo.VO;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UserDao implements IDAO {
    @Override
    public boolean insert(VO vo) throws SQLException {
        MysqlDB conn = new MysqlDB();
        //执行游标
        PreparedStatement ps = conn.getConn().prepareStatement("insert into easybuy_user(eu_user_name,eu_password) values(?,?)");
        //创建users类对象
        Users users = (Users) vo;
        //为问号赋值
        ps.setString(1, users.getEu_user_name());
        ps.setString(2, users.getEu_password());
        //执行sql语句，成功即返回1
        int i = ps.executeUpdate();
        //关闭连接
        conn.closeConn();
        return i > 0;
    }

    @Override
    public boolean login(VO vo) throws SQLException {
        MysqlDB conn = new MysqlDB();
        PreparedStatement ps = conn.getConn().prepareStatement("select * from easybuy_user where eu_user_name=? and eu_password=?");
        Users users = (Users) vo;
        ps.setString(1, users.getEu_user_name());
        ps.setString(2, users.getEu_password());
        ResultSet rs = null;
        //执行sql语句
        rs = ps.executeQuery();
        conn.closeConn();
        //返回是否查询到内容
        return rs.next();
    }


    @Override
    public List getAll() throws SQLException {
        return null;
    }
}
